package com.itsv.news.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.itsv.news.R;
import com.itsv.news.bean.VideoBean;
import com.itsv.news.utils.AsyncImageLoader;
import com.itsv.news.utils.ImageUtils;

public class HorizontalListViewAdapter extends BaseAdapter{
	
	private List<VideoBean> vblist=new ArrayList<VideoBean>();
	
	public List<VideoBean> getVblist() {
		return vblist;
	}
	public void setVblist(List<VideoBean> vblist) {
		this.vblist = vblist;
	}
	public HorizontalListViewAdapter(Context con,List<VideoBean> list){
		context =con;
		vblist=list;
		mInflater=LayoutInflater.from(context);
	}
	public HorizontalListViewAdapter(Context con){
		context =con;
	}
	@Override
	public int getCount() {
		if(vblist==null)
			return 0;
		else
			return vblist.size();
	}
	private Context context;
	private LayoutInflater mInflater;
	@Override
	public Object getItem(int position) {
		return position;
	}
	private ViewHolder vh 	 =new ViewHolder();
	private static class ViewHolder {
		private TextView time ;
		private TextView title ;
		private ImageView im;
	}
	@Override
	public long getItemId(int position) {
		return position;
	}
	private AsyncImageLoader ail = AsyncImageLoader.getInstance();
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(convertView==null)
			convertView = mInflater.inflate(R.layout.horizontallistitem, null);
		vh.im=(ImageView)convertView.findViewById(R.id.iv_pic);
		vh.time=(TextView)convertView.findViewById(R.id.tv_time);
		vh.title=(TextView)convertView.findViewById(R.id.tv_name);
		if(vblist==null||vblist.size()==0){
			vh.time.setText("00:00");
			vh.title.setText("XXXXXX");
		}else{
			vh.time.setText(vblist.get(position).getVideoLength());
			vh.title.setText(vblist.get(position).getVideoName());
			if(ImageUtils.checkImage(vblist.get(position).getFileName())){
				ail.displayImage(vblist.get(position).getFileName(),vh.im,R.drawable.picture_image_bg,true);
			}
		}
		return convertView;
	}
}
